package br.com.adimoveis.util.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JToggleButton;


public class ToggleButton extends JToggleButton {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ToggleButton(String text, Icon icon) {
        super(text,icon);
        setContentAreaFilled(false);
        setFocusPainted(false);
        Dimension d = new Dimension(150, 30);
        setPreferredSize(d);
        setMinimumSize(d);
        setMaximumSize(d);
    }

    @Override
    protected void paintComponent(Graphics g) {
    	
    	Graphics2D g2 = (Graphics2D) g;
    	
    	if(isSelected()){
	        
    		customPaint(g2, Color.WHITE,new Color(255,194,14));
    		setBorder(BorderFactory.createLoweredBevelBorder());
    		
    	}else{
    		
    		customPaint(g2, new Color(235,235,235),new Color(180,180,180));
    		setBorder(BorderFactory.createRaisedBevelBorder());
    		
    	}
    	
        super.paintComponent(g);
    }
    
    private void customPaint(Graphics2D g2, Color iniColor, Color endColor){
    	  GradientPaint p;
	        p = new GradientPaint(0, 0, iniColor, 0, getHeight(),
	                endColor);
	
	        Paint oldPaint = g2.getPaint();
	        g2.setPaint(p);
	        g2.fillRect(0, 0, getWidth(), getHeight());
	        g2.setPaint(oldPaint);
	        
	        setBorder(BorderFactory.createLineBorder(new Color(180,180,180)));
    }


}
